package com.astudio.lhasa.workers.ai.map;

import com.astudio.lhasa.workers.ai.map.interfaces.IMapAroundSearchCallback;
import com.astudio.lhasa.workers.ai.map.modules.MapLocation;

public class MapLocationManager {
    private static volatile MapLocationManager instance = null;
    private BaseVendorMap baseVendorMap = null;

    private MapLocationManager() {
    }

    public static MapLocationManager getInstance(BaseVendorMap map) {
        if (instance == null) {
            synchronized (MapLocationManager.class) {
                instance = new MapLocationManager();
            }
        }

        if (map != null) {
            instance.setMap(map);
        }

        return instance;
    }

    public void setMap(BaseVendorMap map) {
        baseVendorMap = map;
    }

    public void initMap() {
        if (baseVendorMap != null) {
            baseVendorMap.init();
        }
    }

    public void turnOnMap() {
        if (baseVendorMap != null) {
            baseVendorMap.start();
        }
    }

    public void turnOffMap() {
        if (baseVendorMap != null) {
            baseVendorMap.terminate();
        }
    }

    public MapLocation getLocation() {
        if (baseVendorMap != null) {
            return baseVendorMap.getLocation();
        }
        return null;
    }

    public void searchAroundAsync(String key, int limit, IMapAroundSearchCallback callback) {
        if (baseVendorMap != null) {
            baseVendorMap.searchAroundAsync(key, limit, callback);
        }
    }
}
